class SearchbooksController < ApplicationController
  def new    
    @user = current_user
    @categories = Category.all
    @hot_books = Book.search_hot_book()    

    @search_option = params[:search_option].to_i

    if (@search_option == nil)
      @search_option = 0  
    end

    case @search_option
    when 0 then @books = Kaminari.paginate_array(Book.search(params[:search])).page(params[:page]).per(3)
    when 1 then @books = Kaminari.paginate_array(Book.search(params[:search])).page(params[:page]).per(3)
    when 2 then @books = Kaminari.paginate_array(Book.search(params[:search])).page(params[:page]).per(3)
    end

  end

  def show
    @searchoption = params[:search_options]

    if (@searchoption != nil)
      redirect_to searchbooks_new_path(:search_options => params[:search_options])
    else
      redirect_to login_url
    end
  end
end
